﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using My.GenCode.Entities;
using My.GenCode.Interface;

namespace My.GenCode.Templates
{
    public class GenDetailPage : CodeTemplate
    {
        #region 覆盖父类的方法

        public GenDetailPage(string tpl, EntityInfo info, string desc) : base(tpl, info, desc) { }

        protected override string ProcTemplate()
        {
            _tpl = this.LoopProperties(_tpl, "<<ContentItemsCodeBlock>>", this.ContentItemsCodeBlock);
            _tpl = this.LoopProperties(_tpl, "<<FormItemsCodeBlock>>", this.FormItemsCodeBlock);

            _tpl = _tpl.Replace("<FileName>", _nh.ReadDetailPageFileName);             // 处理<FileName>标签
            _tpl = _tpl.Replace("<<NameSpace>>", _nh.NameSpace);                       // 处理<<NameSpace>>标签
            _tpl = _tpl.Replace("<<EntityName>>", _nh.EntityName);                     // 处理<<EntityName>>标签
            _tpl = _tpl.Replace("<<EntityClassName>>", _nh.EntityName);                // 处理<<EntityClassName>>标签
            _tpl = _tpl.Replace("<<HandlerClassName>>", _nh.EntityName);               // 处理<<EntityClassName>>标签

            _tpl = _tpl.Replace("<<ReadDetailMethodName>>", _nh.ReadDetailMethodName); // 处理<<DetailMethodName>>标签
            _tpl = _tpl.Replace("<<UpdateMethodName>>", _nh.UpdateMethodName);         // 处理<<UpdateMethodName>>标签

            return _tpl;
        }
        
        protected override string OutputFilename()
        {
            return @"Website\_Subpages\" + _nh.ReadDetailPageFileName;
        }

        #endregion

        #region 私有方法,处理模板的循环标签

        private string FormItemsCodeBlock(string tpl,PropertyInfo info)
        {
            tpl = tpl.Replace("<<Name>>", info.Name);
            return tpl;
        }

        private string ContentItemsCodeBlock(string tpl, PropertyInfo info)
        {
            tpl = tpl.Replace("<<Name>>", info.Name);
            return tpl;
        }

        #endregion
    }
}